//
//  StowView.m
//  MyTravel
//
//  Created by Hunk on 11-5-27.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "StowView.h"
#import <QuartzCore/QuartzCore.h>
#import "MyTravelAppDelegate.h"

@implementation StowView

- (id)initWithFrame:(CGRect)frame flag:(NSString*)flag withName:(NSString*)name
{
    self = [super initWithFrame:frame];
    if (self) 
    {   
        // bgView
        UIView* bgView = [[UIView alloc] initWithFrame:CGRectMake((320 - 120) / 2 , (480 - 80) / 2, 120, 80)];
        [bgView setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.95f]];
        bgView.layer.cornerRadius = 10.0f;
        bgView.layer.masksToBounds = YES;
        
        // Flag label
        UILabel* flagLabel = [[UILabel alloc] initWithFrame:CGRectMake((bgView.frame.size.width - 30)/2, (bgView.frame.size.height - 30)/2 - 15, 30, 30)];
        [flagLabel setBackgroundColor:[UIColor clearColor]];
        [flagLabel setTextColor:[UIColor whiteColor]];
        [flagLabel setTextAlignment:UITextAlignmentCenter];
        [flagLabel setText:flag];
        [bgView addSubview:flagLabel];
        
        // Name label
        UILabel* nameLabel = [[UILabel alloc] initWithFrame:CGRectMake((bgView.frame.size.width - 120)/2, (bgView.frame.size.height - 80)/2 + 15, 120, 80)];
        [nameLabel setBackgroundColor:[UIColor clearColor]];
        [nameLabel setTextColor:[UIColor whiteColor]];
        [nameLabel setTextAlignment:UITextAlignmentCenter];
        [nameLabel setText:name];
        [bgView addSubview:nameLabel];
        [flagLabel release];
        [nameLabel release];
        
        [self addSubview:bgView];
        [bgView release];
    }
    return self;
}

- (void)viewWillDisappear
{
    MyTravelAppDelegate* appDelegate = (MyTravelAppDelegate*)[[UIApplication sharedApplication] delegate];
    [appDelegate.window addSubview:self];
    
    [UIView beginAnimations:@"View will disappear" context:nil];
    
    [UIView setAnimationDuration:1.2f];
    
    [self setAlpha:0.0];
    
    [UIView commitAnimations];
}

- (void)dealloc
{
    [super dealloc];
}

@end
